// pages/index/index.js
var app = getApp();
import newhost from "../../host.js";
Page({
  /**
   * 页面的初始数据
   */
  data: {
    store_id: newhost.store_id
  },

  // 小程序是否可回平台
  _getStoreInformation() {
    return new Promise((resolve, reject) => {
      const { store_id } = this.data;
      const urlStr = app.getNetAddresss("plugin.store-cashier.frontend.store.store-home.get-store-information");
      app._getNetWork({
        url: urlStr,
        data: { store_id },
        success: function(res) {
          resolve(res)
        },
        fail: function(err) {
          reject(err)
        }
      })
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    if (options.scene) {
      let scene = decodeURIComponent(options.scene);
      if (scene) {
        let info_arr = [];
        info_arr = scene.split(",");
        for (let i = 0; i < info_arr.length; i++) {
          let chil_arr = [];
          chil_arr = info_arr[i].split("=");
          if (chil_arr[0] == "mid") {
            app._setMid(chil_arr[1]);
          }
        }
      }
    }

    if (options.mid) {
      app._setMid(options.mid);
    }
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {},

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: async function () {
    if(newhost.diyHomeUrl && !app._isTextEmpty(newhost.diyHomeUrl)){
      wx.reLaunch({
        url: newhost.diyHomeUrl,
      })
      return
    }

    let reLaunchUrl = '/packageG/index/index';
    if(this.data.store_id) {
      reLaunchUrl = '/packageG/o2o/HomeSeller/HomeSeller?store_id=' + this.data.store_id;
    }
    // if (this.data.store_id) {
    //   let getStoreInfo = await this._getStoreInformation();
    //   const { data, result } = getStoreInfo.data
    //   if(result == 1) {
    //     const storeData = data.data;
    //     const { return_platfrom } = storeData;
    //     if(return_platfrom == 0) {
    //       reLaunchUrl = '/packageC/o2o/HomeSeller/HomeSeller?store_id=' + this.data.store_id;
    //     }
    //   }
    // }

    wx.reLaunch({
      url: reLaunchUrl,
    });
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {},

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {},

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {},

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {},

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {},
});
